package main

import (
	"fmt"

	"golang.org/x/tools/container/intsets"
	"gxgeek.com/gxgeek/learngo/lang/tree/tree"
)

type MyTreeNode struct {
	node *tree.Node
}

func (mynode *MyTreeNode) postOrder() {
	if mynode == nil || mynode.node == nil {
		return
	}
	left := MyTreeNode{mynode.node.Left}
	left.postOrder()
	right := MyTreeNode{mynode.node.Rigth}
	right.postOrder()
	mynode.node.Print()

}
func main() {
	//3
	//0      5
	//2  4
	var root tree.Node
	root = tree.Node{Value: 3}
	root.Left = &tree.Node{}
	root.Rigth = &tree.Node{5, nil, nil}
	root.Rigth.Left = new(tree.Node)
	root.Left.Rigth = tree.CreateNode(2)
	root.Rigth.Left.SetValue(4)
	root.Traverse()
	//fmt.Println()
	//mynode := MyTreeNode{&root}
	//mynode.postOrder()
	//var pRoot  *tree.Node
	////pRoot.print()
	////fmt.Println()
	//pRoot.SetValue(100)
	//pRoot = &root
	//pRoot.Print()
	////fmt.Println()
	//root.Print()
	//
	//nodes := [] Node{
	//	{value:3},
	//	{},
	//	{6,nil,&root},
	//}
	//fmt.Println(nodes)

	//testSparse()

	nodeCount := 0
	root.TraverseFunc(func(node *tree.Node) {
		nodeCount ++
	})
	fmt.Println("NodeCount:",nodeCount)

	channels := root.TraverseWithChannel()
	maxNode := 0
	for node := range channels {
		if node.Value > maxNode {
			maxNode = node.Value
		}
	}
	fmt.Println("Max Node Value ",maxNode)
}
func testSparse() {
	s := intsets.Sparse{}

	s.Insert(1)
	s.Insert(20000)
	s.Insert(30000)
	fmt.Println(s.Has(1))
	fmt.Println(s.Has(2))
}
